package top.hg.tool.common.util;

import lombok.Data;

import java.io.Serializable;

/**
 * 响应信息主体
 */
@Data
public class R<T> implements Serializable {

	private static final long serialVersionUID = 1L;

	public static final int FAIL = -1;

	public static final int SUCCESS = 1;

	private String msg = "success";

	private int code = SUCCESS;

	private T data;

	public static R success() {
		return R.success(null);
	}

	public static R success(Object data) {
		R r = new R();
		r.setCode(SUCCESS);
		r.setData(data);
		r.setMsg("success");
		return r;
	}

	public static R error(String msg) {
		return R.error(FAIL, msg);
	}
	
	public static R error(int code,String msg) {
		R r = new R();
		r.setCode(code);
		r.setData(null);
		r.setMsg(msg);
		return r;
	}


	public R() {
		super();
	}


}
